package com.push.notifications;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.webkit.WebSettings;

import android.widget.TextView;

public class MessageActivity extends Activity{
	public static float scale= 1;
	
	public static String messageCataloge;
	public static String messageConent;
	public static String title;
	public static String url;
	

	
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		 setContentView(R.layout.message_full);
		//RelativeLayout layot = (RelativeLayout) findViewById(R.id.mesage20);
		
		TextView CatalogMessage = (TextView) findViewById(R.id.TitleMssage);
		CatalogMessage.setText(messageCataloge);
		WebViewBasic webmesage = (WebViewBasic) findViewById(R.id.webMessage) ;
	
		webmesage.setHorizontalScrollBarEnabled(false);
		webmesage.setScrollbarFadingEnabled(false);
		WebSettings webSettings = webmesage.getSettings();
		if(url != null &&url.equalsIgnoreCase(""))
		{
			webmesage.loadData(messageConent, "text/html", "UTF-8");
		}
		else
		{
			Display display = getWindowManager().getDefaultDisplay();
	        int width = display.getWidth();
	        int height = display.getHeight();
	        float webScale = webmesage.getScale();
			int nWidth = (int)(width/webScale);
			url = url + "&width="+nWidth+"&title="+title;
			webmesage.loadUrl(url);
		}
			
	}
	
	public static float convertDpToPixel(float dp,Context context){
	    Resources resources = context.getResources();
	    DisplayMetrics metrics = resources.getDisplayMetrics();
	    float px = dp * (metrics.densityDpi/160f);
	    return px;
	}
	
	@Override
	protected void 	onUserLeaveHint(){
		GCMIntentService.AppInterrupt =true;
		Log.e("onUserLeaveHint", "onUserLeaveHint: ------onUserLeaveHint------------ MessageActivity-"+GCMIntentService.AppInterrupt);
		super.onUserLeaveHint();
	}
	@Override
	protected void onStart() {
		super.onStart();
	}
	@Override
	protected void onStop() {
		Log.e("MessageActivity", "onStop: ------onStop------------ -"+GCMIntentService.AppInterrupt);
		if(GCMIntentService.AppInterrupt )
		{
			if  ( !(historyNewsCategory.isDie) )
			{
				historyNewsCategory.han_historyNewsCategory.sendEmptyMessage(0);
			}
			else
			{
				HistoryActivity.han_history.sendEmptyMessage(0);
			}
			NotificationActivity.han_notification.sendEmptyMessage(0);
			finish();
		}

		super.onStop();
	}
	  @Override
	  	public void onWindowFocusChanged(boolean hasFocus) {
		  if (hasFocus)
		  {
			  GCMIntentService.AppInterrupt =false;
		  }
		// TODO Auto-generated method stub
		  Log.e("MessageActivity", ": ------onWindowFocusChanged------------ onWindowFocusChanged-"+GCMIntentService.AppInterrupt);
		super.onWindowFocusChanged(hasFocus);
	  	}
	
}
